package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SaleRebatesRulesAddDTO;
import org.jsola.hr.dto.SaleRebatesRulesUpdateDTO;
import org.jsola.hr.entity.SaleRebatesRulesDO;
import org.jsola.hr.query.SaleRebatesRulesQuery;
import org.jsola.hr.service.ISaleRebatesRulesService;
import org.jsola.hr.vo.SaleRebatesRulesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 返费规则
 *
 * @author zhr
 */
@Component
public class SaleRebatesRulesTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISaleRebatesRulesService saleRebatesRulesService;

    /**
     * 生成add测试数据
     * @return SaleRebatesRulesAddDTO
     */
    public SaleRebatesRulesAddDTO getSaleRebatesRulesAddDTO(){
        SaleRebatesRulesAddDTO saleRebatesRulesAddDTO = new SaleRebatesRulesAddDTO();
        saleRebatesRulesAddDTO.setRulesName(getRandomValue("varchar",50));
        saleRebatesRulesAddDTO.setSubjectType(getRandomValue("varchar",50));
        saleRebatesRulesAddDTO.setRegion(getRandomValue("varchar",50));
        saleRebatesRulesAddDTO.setNewProportion(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRulesAddDTO.setContinueProportion(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRulesAddDTO.setRemark(getRandomValue("varchar",255));
        return saleRebatesRulesAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SaleRebatesRulesUpdateDTO
     */
    public SaleRebatesRulesUpdateDTO getSaleRebatesRulesUpdateDTO(SaleRebatesRulesVO saleRebatesRulesVO){
        return saleRebatesRulesService.selectDOById(saleRebatesRulesVO.getId(), SITE_ID).to(SaleRebatesRulesUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SaleRebatesRulesQuery
     */
    public SaleRebatesRulesQuery getSaleRebatesRulesQuery() {
        SaleRebatesRulesQuery saleRebatesRulesQuery = new SaleRebatesRulesQuery();
        List<SaleRebatesRulesDO> saleRebatesRulesDOList = saleRebatesRulesService.list(new SaleRebatesRulesDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(saleRebatesRulesDOList)) {
            SaleRebatesRulesDO saleRebatesRulesDO = saleRebatesRulesDOList.get(0);
            saleRebatesRulesQuery = saleRebatesRulesDO.to(SaleRebatesRulesQuery.class);
        }
        return saleRebatesRulesQuery;
    }

    /**
     * 保存示例
     * @return SaleRebatesRulesVO
     */
    public SaleRebatesRulesVO saveSaleRebatesRulesExample(){
        SaleRebatesRulesAddDTO addDTO = this.getSaleRebatesRulesAddDTO();
        SaleRebatesRulesVO saleRebatesRulesVO = saleRebatesRulesService.save(addDTO,buildTokenUser());
        return saleRebatesRulesVO;
    }


}

